package org.kjtc.entity;

import org.apache.commons.lang.StringUtils;

public class Template {

    // 接收者openid
	private String toUser;
    // 模板ID
    private String templateId;
    // 模板跳转链接
    private String url;
    // 模板消息顶部颜色
    private String topColor;
    // 所需跳转到的小程序appid（该小程序appid必须与发模板消息的公众号是绑定关联关系）
    private String appid;
    // 所需跳转到小程序的具体页面路径，支持带参数,（示例index?foo=bar）
    private String pagepath;
    // 模板数据
    private String data;

    public String getToUser() {
        return toUser;
    }

    public void setToUser(String toUser) {
        this.toUser = toUser;
    }
  
    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getTopColor() {
        return topColor;
    }

    public void setTopColor(String topColor) {
        this.topColor = topColor;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getPagepath() {
        return pagepath;
    }

    public void setPagepath(String pagepath) {
        this.pagepath = pagepath;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String toJSON() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("{");
        buffer.append(String.format("\"touser\":\"%s\"", this.toUser)).append(",");
        buffer.append(String.format("\"template_id\":\"%s\"", this.templateId)).append(",");
        if (!StringUtils.isEmpty(this.url)) {
            buffer.append(String.format("\"url\":\"%s\"", this.url)).append(",");
        }
        buffer.append(String.format("\"topcolor\":\"%s\"", this.topColor)).append(",");
        if (!StringUtils.isEmpty(this.appid) && !StringUtils.isEmpty(this.pagepath)) {
            buffer.append("\"miniprogram\":{");
            buffer.append(String.format("\"appid\":\"%s\"", this.appid)).append(",");
            buffer.append(String.format("\"pagepath\":\"%s\"", this.pagepath));
            buffer.append("}").append(",");
        }
        buffer.append(String.format("\"data\":%s", this.data));
        buffer.append("}");
        return buffer.toString();
	}
}